package com.m4f.appengine.utils.security.user.registry;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.springframework.util.Assert;

public class InMemoryUserRegistry implements UserRegistry {
	
	private static final Logger LOGGER = Logger
	.getLogger(InMemoryUserRegistry.class.getName());
	
	private final Map<String, AppUser> users = 
		Collections.synchronizedMap(new HashMap<String, AppUser>());

    public AppUser findUser(String userId) {
        return users.get(userId);
    }

    public void registerUser(AppUser newUser) {
        LOGGER.info("Attempting to create new user " + newUser);
        Assert.state(!users.containsKey(newUser.getUserId()));
        users.put(newUser.getUserId(), newUser);
    }

    public void removeUser(String userId) {
        users.remove(userId);
    }
    
}	